<?php
namespace app\common\model;
use think\Model;
class AuthRule extends Model
{
	/**/
	public function getAll(){
		$rows = self::order("sort asc")->select();
		return $rows;
	}

	//获取顶级菜单:系统管理,应用管理
	public function getTopMenu(){
		return (array) db('auth_rule')->where(array('status'=>1,'pid'=>0))->order('sort asc')->select();
	}

	public function getLeftNavs($pid){
		$navs = $this->rules();
		$nav = new \clt\Leftnav();
		$arrai = $nav->menu($navs,"",$pid);
		//echo "<pre>";
		//print_r($navs);exit;
		return $arrai;
	}
	public function rules(){
		$navs = '';//S("rules_all");
		if(empty($navs)){
			$navs = db('auth_rule')->where(array('status'=>1))->order('sort asc')->column("id,title,pid,status,onclick,href,menu_status","id");
			 //S("rules_all",$navs);
		}
		return $navs;
	}
	public function genRulesTree(){
		$tree = '';//S("rules_tree");
		if(empty($tree)){
			$items = $this->rules();
			$tree = array();
		    foreach($items as $item){
		        if(isset($items[$item['pid']]))
		            $items[$item['pid']]['son'][] = &$items[$item['id']];
		        else 
		            $tree[] = &$items[$item['id']];
		    }
		}
		return $tree;
		
	}

}